﻿//-----------------------------------------------------------------------
// <copyright file="Helpers.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.XamlUtility
{
    using System.Windows;
    using System.Windows.Media.Animation;

    /// <summary>
    /// Helper methods on XAML types
    /// </summary>
    public static class Helpers
    {
        /// <summary>
        /// Convert boolean to visibility
        /// </summary>
        /// <param name="value">the boolean</param>
        /// <returns>the visibility</returns>
        public static Visibility ToVisibility(this bool value)
        {
            return value ? Visibility.Visible : Visibility.Collapsed;
        }

        /// <summary>
        /// Turn Visible to collapsed and vice versa
        /// </summary>
        /// <param name="value">the value to invert</param>
        /// <returns>the inverted value</returns>
        public static Visibility Invert(this Visibility value)
        {
            return value == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
        }

        /// <summary>
        /// Find a style resource
        /// </summary>
        /// <param name="element">the element whose resources to inspect</param>
        /// <param name="resourceName">the style's name</param>
        /// <returns>the style found</returns>
        public static Style FindStyle(this FrameworkElement element, string resourceName)
        {
            return element.FindResource(resourceName) as Style;
        }

        /// <summary>
        /// Find a storyboard resource
        /// </summary>
        /// <param name="element">the element whose resources to inspect</param>
        /// <param name="resourceName">the Storyboard's name</param>
        /// <returns>the Storyboard found</returns>
        public static Storyboard FindStoryboard(this FrameworkElement element, string resourceName)
        {
            return element.FindResource(resourceName) as Storyboard;
        }
    }
}
